package com.bootdo.system.service.impl;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.R;
import com.bootdo.common.utils.ShiroUtils;
import com.bootdo.system.dao.PunchBackgroundDao;
import com.bootdo.system.domain.TbPunchBackground;
import com.bootdo.system.domain.UserDO;
import com.bootdo.system.service.PunchBackgroundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @create 2021-03-08 22-02
 */
@Service
public class PunchBackgroundServiceImpl implements PunchBackgroundService {

    @Autowired
    private PunchBackgroundDao punch;

    @Override
    public PageUtils selectPunchBackgroundList(Map map) {
        UserDO user = ShiroUtils.getUser();
        List list = punch.selectPunchBackgroundList(map);
        int selectcount = punch.selectcount(map);
        PageUtils pageUtils = new PageUtils(list,selectcount);
        return pageUtils;
    }

    @Override
    public R addPunchBackground(TbPunchBackground background) {
        UserDO user = ShiroUtils.getUser();
        Long userId = user.getUserId();
        background.setAdminId(userId);
        Map map = new HashMap();
        map.put("adminId",userId);
        int selectcount = punch.selectcount(map);
        if(selectcount + 1 >3){
            return R.error("添加图片不得大于3张!");
        }
        punch.addPunchBackground(background);
        return R.ok();
    }

    @Override
    public void updatePunchBackground(TbPunchBackground background) {
        punch.updatePunchBackground(background);
    }
}
